<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	public $base_dir = 'data/upload/';

	public function __construct()
	{
		parent::__construct();

		$this->load->helper('directory');
		$this->load->helper('url');
		$this->load->helper('haowt');
		$this->_data['img_arr'] = array('jpg', 'jpeg', 'png', 'gif');

		
	}

	public function index()
	{
		$all_dir = directory_map('data/upload', 2);

		$fs = array();
		$ds = array();

		foreach ($all_dir as $key => $value) {
			if (is_array($value)) {
				$ds[] = get_file_name($key);
				/*if (is_windows()) {
					$ds[] = iconv("GBK", "UTF-8", $key);
				} else {
					$ds[] = $key;
				}*/
				// $ds[] = iconv("GBK", "UTF-8", $key); //$key;
			} else {
				$fs[] = get_file_name($value);
				/*if (is_windows()) {
					$fs[] = iconv("GBK", "UTF-8", $value);
				} else {
					$fs[] = $value;
				}*/
				// $fs[] = iconv("GBK", "UTF-8", $value); //$value;
			}
		}

		// var_dump($fs);
		// var_dump($ds);
		
		$this->_data['ds'] = $ds;
		$this->_data['fs'] = $fs;
		$this->load->view('welcome', $this->_data);
	}

	public function get_list() {
		$folder_name = $this->input->post('folder_name', TRUE);
		$path = $this->base_dir.$folder_name;

		if (is_dir($path)) {
			$all_dir = directory_map($path, 2);

			$fs = array();
			$ds = array();

			foreach ($all_dir as $key => $value) {
				if (is_array($value)) {
					$ds[] = get_file_name($key);
				} else {
					$fs[] = get_file_name($value);
				}
			}
			
			$this->_data['ds'] = $ds;
			$this->_data['fs'] = $fs;
			
			$file_list = $this->load->view('file_list', $this->_data, TRUE);
			echo $file_list;
		}

		
	}

	public function create_folder() {
		$folder_name = $this->input->post('folder_name', TRUE);
		$cur_dir = $this->input->post('cur_dir', TRUE);
		
		$cur_dir = rtrim($cur_dir, '/').'/';

		$path = $this->base_dir.$cur_dir.$folder_name;

		$path = create_file_name($path);

		if (@mkdir($path)) {
			echo "yes";
		} else {
			echo "no";
		}

	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */